<?php

/**
 * @author thihien
 * @copyright 2011
 */

require_once('includes/general.php');
if(!tep_db_checkDb()) die('khong ket noi dc csdl');
$masanpham=$_GET['masanpham'];
$sql='SELECT count(id) as count FROM `tbl_chi_tiet_san_pham` where ma_san_pham='.$masanpham;
$kq=tep_db_query($sql);
$item1=tep_db_fetch_array($kq);
//bat dau viet phan trang
$display=9;// so san pham xuat hien tren mot trang
$record=$item1['count'];//tong so san pham
if($record>$display){
    $page=ceil($record/$display);
}
else{
    $page=1;
}
$start=isset($_GET['start']) && (int)$_GET['start']?$_GET['start']:0;
$sql4='select * from tbl_chi_tiet_san_pham where ma_san_pham='.$masanpham.' limit '.$start.', '.$display.'';
$kq4=tep_db_query($sql4);
$sql2='select ten_san_pham from tbl_san_pham where id='.$masanpham;
$kq2=tep_db_query($sql2);
$item2=tep_db_fetch_array($kq2);
$content='';
$content.='
    <div id="center" >
        <div class="tt_sanpham">
            <div class="tieude_center" id="tieude_hoatdong_center" ><h3>'.$item2['ten_san_pham'].'</h3></div>';
            if($record!=0){
        while($item=tep_db_fetch_array($kq4)){
            $content.='
             
            <div class="show_sanpham">
                <div class="hinhanh_sp"><a href="?page=sanphamkhcn&machitietsp='.$item['id'].'&masanpham='.$item['ma_san_pham'].'&mode=detail"><img  height="130" width="150" src="admincp/upload/'.$item['anh_san_pham'].'"/></a></div>
                
                <div class="tieude_sp">
                    <div class="tensp" style="margin-top: 8px;">'.$item['ten_chi_tiet_san_pham'].'</div>
                    <div class="ct"><a href="?page=sanphamkhcn&machitietsp='.$item['id'].'&masanpham='.$item['ma_san_pham'].'&mode=detail">Chi Tiết...</a></div>
                </div>
            </div>
                
                ';
                
        }
        
$content.='
        <ul class="phantrang">';
         $content.='Trang:';
            if($page>1){
                $next=$start+$display;
                $prev=$start-$display;
                $current=($start/$display)+1;
                //hien thi phan trang prev
               
                if($current!=1){
                   $content.='<li><a href="?page=sanphamkhcn&masanpham='.$masanpham.'&start='.$prev.'">Previous</a></li>'; 
                }
                 //hien thi trang
                 for($i=1;$i<=$page;$i++){
                   if($current!=$i){
                        $content.='<li><a href="?page=sanphamkhcn&masanpham='.$masanpham.'&start='.$display*($i-1).'">'.$i.'</a></li>'; 
                    } 
                    else
                    {
                       $content.='<li class="current"><a href="?page=sanphamkhcn&masanpham='.$masanpham.'&start='.$display*($i-1).'">'.$i.'</a></li>'; 
                    }
                     
                 }
                //hien thi next
                if($current!=$page){
                    $content.='<li><a href="?page=sanphamkhcn&masanpham='.$masanpham.'&start='.$next.'">Next</a></li>';  
                }
            }
            else{
                $content.='<li class="current" ><a href="?page=sanphamkhcn&masanpham='.$masanpham.'&start='.$page.'">'.$page.'</a></li>';  
            }
       $content.=' </ul>';}
       else{
        $content.='<div class="tt">Thông tin đang cập nhật....</div>';
       }
   $content.='</div>
    </div> 
';
if(isset($_GET['mode']) && $_GET['mode']=='detail'){
$masanpham=$_GET['masanpham'];
$machitietsp=$_GET['machitietsp'];
$sql='select * from tbl_chi_tiet_san_pham where id='.$machitietsp;
$kq=tep_db_query($sql);

$content='
    <div id="center">
        <div class="tt_sanpham">
            <div class="tieude_center" id="tieude_ctsp"><h3>Sản phẩm</h3></div>';
        while($item=tep_db_fetch_array($kq)){
            $content.='
             
            
            <div class="noidung">
                <div class="hinhanh"><img style="border:1px solid gray;" height="300" width="400" src="admincp/upload/'.$item['anh_san_pham'].'"/>
                   
                </div>
                <div class="ten_ctsp">
                     <table class="chitietsanpham" cellspacing="5" cellpadding="5">
                            <tr style="margin-top: 5px;">
                                <td class="ten_mota" >Tên Sản Phẩm</td>
                                <td class="mota">'.$item['ten_chi_tiet_san_pham'].'</td>
                            </tr>
                            <tr style="margin-top: 5px;">
                                <td class="ten_mota"  >Mã Sản Phẩm</td>
                                <td class="mota" >'.$item['ma_chi_tiet_san_pham'].'</td>
                            </tr>
                            <tr style="margin-top: 5px;">
                                <td class="ten_mota" valign="middle" >Tác Giả</td>
                                <td class="mota" >'.$item['tac_gia'].'</td>
                            </tr>
                            <tr style="margin-top: 5px;">
                                <td class="ten_mota" valign="middle" >Thuộc Lĩnh Vực</td>
                                <td class="mota">'.$item['thuoc_linh_vuc'].'</td>
                            </tr>
                            <tr style="margin-top: 5px;">
                                <td class="ten_mota" valign="middle" >Mô Tả Sản Phẩm</td>
                                <td class="mota">'.$item['mo_ta_san_pham'].'</td>
                            </tr>
                            <tr style="margin-top: 5px;">
                                <td class="ten_mota" valign="middle" >Địa Bàn Ứng Dụng</td>
                                <td class="mota" style="margin-top: 5px;">'.$item['dia_ban_ung_dung'].'</td>
                            </tr>
                            <tr style="margin-top: 5px;">
                                <td class="ten_mota" >Địa Bàn Liên Hệ</td>
                                <td class="mota">'.$item['dia_ban_lien_he'].'</td>
                            </tr>
                    </table>
                </div>
                

            </div>
                
                ';
                
        }
$sql='SELECT count(id) as count FROM `tbl_chi_tiet_san_pham` where id!='.$machitietsp.' and ma_san_pham='.$masanpham ;
$kq=tep_db_query($sql);
$item1=tep_db_fetch_array($kq);
//bat dau viet phan trang
$display=3;// so san pham xuat hien tren mot trang
$record=$item1['count'];//tong so san pham
if($record>$display){
    $page=ceil($record/$display);
}
else{
    $page=1;
}
$start=isset($_GET['start']) && (int)$_GET['start']?$_GET['start']:0;
$sql4='select * from tbl_chi_tiet_san_pham where ma_san_pham='.$masanpham.' and id!='.$machitietsp.' limit '.$start.', '.$display.'';
$kq4=tep_db_query($sql4);
$content.=' </div>  
    <div class="tt_sanpham">
            <div class="tieude_center" id="tieude_spcungloai"><h3>sản phẩm cùng loại</h3></div>';
            while($item1=tep_db_fetch_array($kq4)){
            $content.='
             
            <div class="show_sanpham">
                <div class="hinhanh_sp"><a href="?page=sanphamkhcn&machitietsp='.$item1['id'].'&masanpham='.$masanpham.'&mode=detail"><img  height="130" width="150" src="admincp/upload/'.$item1['anh_san_pham'].'"/></a></div>
                
                <div class="tieude_sp">
                    <div class="tensp" style="margin-top: 5px;">'.$item1['ten_san_pham'].'</div>
                    <div class="ct"><a href="?page=sanphamkhcn&machitietsp='.$item1['id'].'&masanpham='.$masanpham.'&mode=detail">Chi Tiết...</a></div>
                </div>
            </div>
                
                ';
                
        }

        
  $content.='</div>
        <ul class="phantrang">';
         $content.='Trang:';
            if($page>1){
                $next=$start+$display;
                $prev=$start-$display;
                $current=($start/$display)+1;
                //hien thi phan trang prev
               
                if($current!=1){
                   $content.='<li><a href="?page=sanphamkhcn&machitietsp='.$machitietsp.'&masanpham='.$masanpham.'&start='.$prev.'&mode=detail">Previous</a></li>'; 
                }
                 //hien thi trang
                 for($i=1;$i<=$page;$i++){
                   if($current!=$i){
                        $content.='<li><a href="?page=sanphamkhcn&machitietsp='.$machitietsp.'&masanpham='.$masanpham.'&start='.$display*($i-1).'&mode=detail">'.$i.'</a></li>'; 
                    } 
                    else
                    {
                       $content.='<li class="current"><a href="?page=sanphamkhcn&machitietsp='.$machitietsp.'&masanpham='.$masanpham.'&start='.$display*($i-1).'&mode=detail">'.$i.'</a></li>'; 
                    }
                     
                 }
                //hien thi next
                if($current!=$page){
                    $content.='<li><a href="?page=sanphamkhcn&machitietsp='.$machitietsp.'&masanpham='.$masanpham.'&start='.$next.'&mode=detail">Next</a></li>';  
                }
            }
            else{
                $content.='<li class="current" ><a href="?page=sanphamkhcn&machitietsp='.$machitietsp.'&masanpham='.$masanpham.'&start='.$page.'&mode=detail">'.$page.'</a></li>';  
            }
       $content.=' </ul>   
       
    </div> 
';
}
echo $content;

?>
<tr ></tr>